package com.ly.lybatis.builder;

import com.ly.lybatis.session.LyConfiguration;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.InputStream;
import java.util.List;

/**
 * @author liuyang
 * 使用lybatis的初始类，用它来构建LySqlSessionFactory
 */
public class LySqlSessionFactoryBuilder {


    public LySqlSessionFactory build(InputStream inputStream) throws Exception {
        LyConfiguration configuration = new LyConfiguration();
        this.loadConfig(configuration, inputStream);
        return new LySqlSessionFactory(configuration);
    }

    public void loadConfig(LyConfiguration configuration, InputStream inputStream) throws Exception {

        // 使用第三方软件来解析xml文件
        SAXReader saxReader = new SAXReader();

        // 获取到文档对象
        Document document = saxReader.read(inputStream);

        // 获取到property标签元素
        List<Element> list = document.selectNodes("//property");

        for (Element e : list) {

        }
    }

}
